/************************************************************************
 * File: player.h                                                       *
 *                                                                      *
 * Copyright 2006, 2008 Colin Kern (colin.kern@gmail.com)               *
 *                                                                      *
 * This file is part of Profit.  Some previous versions were released   *
 * under the names Megacorp Mania and Acquire.                          *
 *                                                                      *
 * Profit is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU General Public License as published by *
 * the Free Software Foundation, either version 3 of the License, or    *
 * any later version.                                                   *
 *                                                                      *
 * Profit is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 * GNU General Public License for more details.                         *
 *                                                                      *
 * You should have received a copy of the GNU General Public License    *
 * along with Profit.  If not, see <http://www.gnu.org/licenses/>.      *
 ************************************************************************/
#ifndef PLAYER_H
#define PLAYER_H

#include <QWidget>
#include "globals.h"
#include <QList>
#include <QHash>

class Tile;
class QString;
class Company;

class Player : public QWidget
{
    public:
		enum Highlight {
			None,
			Turn,   /* It is this player's turn */
			Merge,  /* It is this player's turn to settle a merge */
			DimTurn /* It is this player's turn, but another player
			           is currently merging */
		};
		
        Player(const QString &name, bool isComputer, QWidget *parent = 0);

        int getMoney() const;
        int nShares(Company *company) const;
        bool isMajority(Company *company) const;
        bool isMinority(Company *company) const;
        int nTiles() const;
        const QString &getName() const;
        const Tile &getTile(int tile) const;
        int getBuyLimit() const;
        bool isComputer() const;
        int getAiDesire(Company *company) const;
		void displayGameResult() const;
		QSize sizeHint() const;
		bool hasTile(const Tile &tile) const;
		QListIterator<Tile> getTileIterator() const;
		bool canSell(Company *company) const;
		bool canTrade(Company *big, Company *small) const;
        
        void reset(const QList<Company*> &companies);
        void giveTile(const Tile &tile);
        void setBuyLimit(int limit);
        void removeTile(const Tile &tile);
        void setMajority(Company *company, bool isMajority = true);
        void setMinority(Company *company, bool isMinority = true);
        void giveShares(Company *company, int amount);
        void takeShares(Company *company, int amount);
        void giveMoney(int amount);
		void takeMoney(int amount);
        void setAiDesire(Company *company, int value);
        void adjustAiDesire(Company *company, int amount);
		void resetAiDesire();
		void givePoints(int amount);
		int getPoints() const;
		void setHighlight(Highlight highlight);
		
	protected:
		void paintEvent(QPaintEvent *event);

    private:
        QString m_name;
        bool m_isComputer;
        int m_money;
        QHash<Company*, int> m_shares;
		QList<Company*> m_keyOrder;
        QList<Tile> m_tiles;
		QHash<Company*, bool> m_isMajority;
		QHash<Company*, bool> m_isMinority;
        int m_buyLimit;
        QHash<Company*, int> m_aiDesires;
		int m_points;
		Highlight m_highlight;
};

#endif
